<?php 
/**
 * Description of form
 * @author diotheos
 * @since 7 мая 2010
 */
class App_Form_Car_Add extends Lib_Form_Clear{
	/**
	 * Initialization of form function
	 * 
	 * @since 7 мая 2010
	 * @author diotheos
	 * @return Zend_Form
	 */
	public function init(){
		parent::init();
		
		$this->setAttrib('enctype', 'multipart/form-data');
		$this->setAction('')
		     ->setMethod('post');
		     
		     
        /**
         * Adding validator chains
         */
		  
		     
		$digitValidator = new Zend_Validate_Digits();
		
		$gtValidator = new Zend_Validate_GreaterThan(0);
		$gtValidator->setMessage('Поле обязательное');
		
		$yearValidator = new Zend_Validate_Between(array(
		    'min' => 1900,
		    'max' => 2010
		));
		$yearValidator->setMessage('Укажите год');
		
		$stringLengthValidator = new Zend_Validate_StringLength(array('min'=>0, 'max'=>400));
		$intValidator = new Zend_Validate_Int();
		
		$phone = new Zend_Form_Element_Text('phone');
		$phone->setAttrib('class', 'required');
		//$phone->setAttrib('minlength', '9');
        $a = new ArrayIterator(array());
		
		$phone->setLabel(_('Ваш телефон'));
		$this->addElement($phone);
		
		/**
		 * Adding filter chains 
		 */
		$textFilter = new Zend_Filter_StripTags();
		
		$category = new Zend_Form_Element_Select('category');
		$category->setAttrib('class', 'styled');
		$category->setRegisterInArrayValidator(false);
		$category->setLabel(_('Категория'));
		
		$category->addValidator($gtValidator, true);
//		
//		$category->addValidators(array(
//		    $digitValidator,
//		    $gtValidator
//		));
		$this->addElement($category);

        $subcategory = new Zend_Form_Element_Select('subcategory');
        $subcategory->setLabel( _('Подкатегория'));
        $subcategory->setRegisterInArrayValidator(false);
        $subcategory->setAttrib('class', 'styled');
        $subcategory->addValidator($intValidator, true);
        
        $this->addElement($subcategory);
        
        $mark = new Zend_Form_Element_Select('mark');
        $mark->setLabel( _('Марка'));
        $mark->setRequired(true);
        $mark->setRegisterInArrayValidator(false);
        $mark->removeDecorator('Errors');
        $mark->removeDecorator('label');
        $mark->setAttrib('class', 'styled');
        
//        $mark->addValidator($digitValidator, true);
		$mark->addValidator($gtValidator, true);
//        $mark->addValidators(array(
//            $intValidator,
//            $gtValidator
//        ));
        $this->addElement($mark);
        
        $model = new Zend_Form_Element_Select('model');
        $model->setLabel( _('Модель'));
        $model->setRequired(true);
        $model->setRegisterInArrayValidator(false);
        $model->removeDecorator('Errors');
        $model->setAttrib('class', 'styled');
//        $model->addValidators(array(
//            $intValidator,
//            $gtValidator
//        ));
        $model->addValidator($gtValidator, true);
        $this->addElement($model);
        
        $state = new Zend_Form_Element_Select('state');
        $state->setLabel( _('Область'));
        $state->setRequired(true);
        $state->setRegisterInArrayValidator(false);
        $state->removeDecorator('Errors');
        $state->setAttrib('class', 'styled');
//        $state->addValidators(array(
//            $digitValidator,
//            $gtValidator
//        ));
        $state->addValidator($gtValidator, true);
        $this->addElement($state);
        
        $city = new Zend_Form_Element_Select('city');
        $city->setLabel( _('Город'));
        $city->setRequired(true);
        $city->setRegisterInArrayValidator(false);
        $city->removeDecorator('Errors');
        $city->setAttrib('class', 'styled');
//        $city->addValidators(array(
//            $digitValidator,
//            $gtValidator
//        ));
        $city->addValidator($gtValidator, true);
        $this->addElement($city);
        
        $year = new Zend_Form_Element_Select('year');
        $year->setLabel( _('Год выпуска'));
        $year->setRequired(true);
        $year->removeDecorator('Errors');
        $year->setRegisterInArrayValidator(false);
        $year->setAttrib('class', 'styled');
        $year->addValidators(array(
            $yearValidator
        ));
        $this->addElement($year);
        
        
        $price = new Zend_Form_Element_Text('price');
        $price->setLabel( _('Цена'));
        $price->addValidator($gtValidator, true);
        $this->addElement($price);
        
        $currency = new Zend_Form_Element_Select('currency');
        $currency->setLabel( _('Валюта'));
        $currency->setAttrib('class', 'styled');
//        $currency->setRequired(true);
        $currency->setRegisterInArrayValidator(false);
//        $currency->addValidators(array(
//            $digitValidator,
//            $gtValidator
//        ));
        $this->addElement($currency);
        
        $description = new Zend_Form_Element_Textarea('description');
        $description->setAttribs(array('cols'=>45, 'rows'=>10));
        $description->addFilter($textFilter);
        $description->addValidator($stringLengthValidator);
        
//        $description->setDecorators();
        $description->setLabel(_('Кратко опишите Ваше авто'));
        $description->setDescription('Не больше 400 символов.');
        $description->removeDecorator('label');
        $description->removeDecorator('description');
        $this->addElement($description);
        
        $exchange = new Zend_Form_Element_Select('exchange');
        $exchange->setLabel( _('Обмен'));
        $exchange->setAttrib('class', 'styled');
        $exchange->setRegisterInArrayValidator(false);
        $exchange->addValidator($intValidator);
        $this->addElement($exchange);
    
        $credit = new Zend_Form_Element_Select('credit');
        $credit->setLabel( _('Кредит'));
        $credit->setAttrib('class', 'styled');
        $credit->setRegisterInArrayValidator(false);
        $this->addElement($credit);
        
     
        $new = new Zend_Form_Element_Select('new');
        $new->setLabel( _('Состояние'));
        $new->setRegisterInArrayValidator(false);
        $new->setAttrib('class', 'styled');
        $this->addElement($new);
       
        $damage = new Zend_Form_Element_Select('damage');
        $damage->setLabel( _('Повреждения'));
        $damage->setAttrib('class', 'styled');
        $damage->setRegisterInArrayValidator(false);
        $this->addElement($damage);

        $custom = new Zend_Form_Element_Select('custom');
        $custom->setLabel( _('Растаможка'));
        $custom->setAttrib('class', 'styled');
        $custom->setRegisterInArrayValidator(false);
        $this->addElement($custom);
        
        $color = new Zend_Form_Element_Select('color');
        $color->setLabel( _('Цвет'));
        $color->setRegisterInArrayValidator(false);
        $color->setAttrib('class', 'styled');
        $this->addElement($color);
        
        $isMetalicColor = new Zend_Form_Element_Checkbox('is_metalic_color');
        $isMetalicColor->setLabel( _('Цвет металик'));
        $this->addElement($isMetalicColor);
        
        $fuel = new Zend_Form_Element_Select('fuel');
        $fuel->setLabel( _('Топливо'));
        $fuel->setAttrib('class', 'styled');
        $fuel->setRegisterInArrayValidator(false);
        $this->addElement($fuel);
        
        $gear = new Zend_Form_Element_Select('gear');
        $gear->setLabel( _('Коробка передач'));
        $gear->setRequired(true);
        $gear->setRegisterInArrayValidator(false);
        $gear->removeDecorator('Errors');
        $gear->addValidator($gtValidator, true);
        $gear->setAttrib('class', 'styled');
        $this->addElement($gear);
        
        $drive = new Zend_Form_Element_Select('drive');
        $drive->setLabel( _('Привод'));
        $drive->setAttrib('class', 'styled');
        $drive->setRegisterInArrayValidator(false);
        $this->addElement($drive);
        
        $mileage = new Zend_Form_Element_Text('mileage');
        $mileage->setLabel( _('Пробег'));
        $mileage->addValidator($digitValidator);
        $this->addElement($mileage);

        $enginePower = new Zend_Form_Element_Text('engine_power');
        $enginePower->setLabel( _('Мощность'). ' ' ._('л.с.'));
        $enginePower->addValidator($digitValidator);
        $this->addElement($enginePower);
        
        $engineVolume = new Zend_Form_Element_Text('engine_volume');
        $engineVolume->setLabel( _('Объем двигателя').' '. _('л.'));
        $this->addElement($engineVolume);

        $doorCount = new Zend_Form_Element_Select('door_count');
        $doorCount->setLabel( _('Количество дверей'));
        $doorCount->setRegisterInArrayValidator(false);
        $doorCount->addValidator($digitValidator);
        $doorCount->setAttrib('class', 'styled');
        $this->addElement($doorCount);
        
        $params = new Zend_Form_Element_MultiCheckbox('params');
        $params->setLabel(_('Параметры'));
        $params->setSeparator('');
        $params->setRegisterInArrayValidator(false);
        $this->addElement($params);
        
        $this->setAttrib('enctype', 'multipart/form-data');
        $file = new Zend_Form_Element_File('photo');
        $file->setLabel(_('Фото'));
        $file->setName('image[]');
        $this->addElement($file);
        
        
        $submit  = new Zend_Form_Element_Submit('add');
        $submit->setLabel(_('Добавить'));
        $this->addElement($submit);
		
        $this->setDecorators(array(
            array('ViewScript', array('viewScript'=>'forms/car/add.phtml', 'class'=> 'form element'))
        ));
        
		return $this;
	}
	
	public function preValidation(){
		
	}
}